<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *积分明细
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'加速明细'),
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(!empty($_RQ['orderid'])){
		$params['orderid']=intval($_RQ['orderid']);
		$return['params']['orderid']=$_RQ['orderid'];
	}
	if(!empty($_RQ['forderid'])){
		$params['forderid']=intval($_RQ['forderid']);
		$return['params']['forderid']=$_RQ['forderid'];
	}
	$params['type']=intval($_RQ['type']);
	$return['params']['type']=$_RQ['type'];
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_cunfeepai_pailog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['price']=pdo_getcolumn('jy_cunfeepai_order',array('id'=>$item['orderid'],'uniacid'=>$_SESSION['uniacid']),'price');
			$item['fee']=price($item['price']*$item['jindu']/100);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		//'export'=>'export',
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：推荐复购都可以加速公排进度！在基本设置里面设置！贡献订单ID：就是下单，产生的排队明细','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'price','title'=>'总免额','type'=>'string'),
			array('name'=>'jindu','title'=>'进度','type'=>'unitstring','unit'=>'%'),
			array('name'=>'fee','title'=>'免额','type'=>'string'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'pailogtype'),
			array('name'=>'pai','title'=>'触发排位','type'=>'string'),
			array('name'=>'orderid','title'=>'所属公排ID','type'=>'string'),
			array('name'=>'forderid','title'=>'贡献订单ID','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'orderid','width'=>15,'title'=>'所属公排ID','type'=>'string'),
			array('name'=>'forderid','width'=>15,'title'=>'贡献订单ID','type'=>'string'),
			array('name'=>'createtime','width'=>15,'title'=>'发生时间','type'=>'time_range'),
			array('name'=>'mid','width'=>15,'title'=>'会员id','type'=>'choose','action'=>'core/member.get_member/'),
		)
	);
	$return['pailogtype']=$this->pailogtype;
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	$params['type']=intval($_RQ['type']);
	$return['params']['type']=$_RQ['type'];
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$list=pdo_getall('jy_cunfeepai_pailog',$params);
	if($list){
		foreach($list as &$item){
			$member=cfc('core')->member_show($item['mid']);
			$item['nickname']=$member['nickname'];
			$item['avatar']=$member['avatar'];
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		}
	}
	$header=array(
		'nickname'=>'用户昵称',
		'jindu'=>'进度',
		'city'=>'城市',
		'createtime'=>'时间',
	);
	cfc('tools')->export2excel($header,$list,'积分日志');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_cunfeepai_pailog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}